package com.ruoyi.web.controller.customer;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.customer.ZeroYuanService;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderMaster;
import com.ruoyi.system.service.customer.ZeroYuanServiceService;
import com.ruoyi.system.service.zhaungxiuservice.shopService.OrderMasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/zero/service")
public class ZeroYuanServiceController extends BaseController {

    @Autowired
    private ZeroYuanServiceService zeroYuanServiceService;
    @Autowired
    private OrderMasterService orderMasterService;


    /**
     * 查询零元质检列表
     */
    @PreAuthorize("@ss.hasPermi('zero:service:list')")
    @GetMapping(value = "/list")
    public TableDataInfo list(ZeroYuanService zeroYuanService)
    {
        startPage();
        List<ZeroYuanService> list = zeroYuanServiceService.selectZeroYuanServiceList(zeroYuanService);
        return getDataTable(list);
    }

    @GetMapping(value = "/orderList/{customerId}")
    public TableDataInfo ordercustomerIdList(@PathVariable("customerId") Integer customerId){
        List<OrderMaster> list =orderMasterService.ordercustomerIdList(customerId);
        return getDataTable(list);
    }

    /**
     * 导出零元质检列表
     */
    @PreAuthorize("@ss.hasPermi('zero:service:export')")
    @Log(title = "零元质检", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZeroYuanService zeroYuanService)
    {
        List<ZeroYuanService> list = zeroYuanServiceService.selectZeroYuanServiceList(zeroYuanService);
        ExcelUtil<ZeroYuanService> util = new ExcelUtil<ZeroYuanService>(ZeroYuanService.class);
        return util.exportExcel(list, "service");
    }

    /**
     * 获取零元质检详细信息
     */
    @PreAuthorize("@ss.hasPermi('zero:service:query')")
    @GetMapping(value = "/{zeroId}")
    public AjaxResult getInfo(@PathVariable("zeroId") Integer zeroId)
    {
        return AjaxResult.success(zeroYuanServiceService.selectZeroYuanServiceById(zeroId));
    }

    /**
     * 新增零元质检
     */
    @PreAuthorize("@ss.hasPermi('zero:service:add')")
    @Log(title = "零元质检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZeroYuanService zeroYuanService)
    {
        return toAjax(zeroYuanServiceService.insertZeroYuanService(zeroYuanService));
    }

    /**
     * 修改零元质检
     */
    @PreAuthorize("@ss.hasPermi('zero:service:edit')")
    @Log(title = "零元质检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZeroYuanService zeroYuanService)
    {
        return toAjax(zeroYuanServiceService.updateZeroYuanService(zeroYuanService));
    }


    /**
     * 多项删除零元质检
     */
    @PreAuthorize("@ss.hasPermi('zero:service:remove')")
    @Log(title = "零元质检", businessType = BusinessType.DELETE)
    @DeleteMapping("/{zeroIds}")
    public AjaxResult remove(@PathVariable Long[] zeroIds)
    {
        return toAjax(zeroYuanServiceService.deleteZeroYuanServiceByIds(zeroIds));
    }

}
